<?php

use yii\helpers\Html;
use yii\widgets\DetailView;

/* @var $this yii\web\View */
/* @var $model backend\models\JjrProject */

$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => 'Jjr Projects', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="jjr-project-view">

    <h1><?= Html::encode($this->title) ?></h1>

    <p>
        <?= Html::a('修改', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
        <?= Html::a('删除', ['delete', 'id' => $model->id], [
            'class' => 'btn btn-danger',
            'data' => [
                'confirm' => 'Are you sure you want to delete this item?',
                'method' => 'post',
            ],
        ]) ?>
    </p>

    <?= DetailView::widget([
        'model' => $model,
        'attributes' => [
            'id',
            'name',
            'price',
              [
                'attribute' => 'main_pic',
                'value' => function($model) {//使用匿名函数格式化（参数为当前模型对象），也可以在模型类中定义该方法
                    $pic = \backend\models\Picture::findOne($model['main_pic']);
                    $path = \yii\helpers\Url::to('@storageUrl/image/'.$pic['path'],true);
                    return Html::img($path,['width'=>'200px','height'=>'100px']);
                },
                  'format'=>'raw'
            ],
            [
                'attribute' => 'real_pic',
                'value' => function($model) {//使用匿名函数格式化（参数为当前模型对象），也可以在模型类中定义该方法
                    $realPics = $model['real_pic']?explode(',',$model['real_pic']):array();
                    $output = '';
                    foreach ($realPics as $realPic){
                        $pic = \backend\models\Picture::findOne($realPic);
                        $path = \yii\helpers\Url::to('@storageUrl/image/'.$pic['path'],true);
                        $output .= Html::img($path,['width'=>'200px','height'=>'100px']);
                    }

                    return $output;
                },
                'label'=>'实景图',
                'format'=>'raw'
            ],
            [
                'attribute' => 'vr_pic',
                'value' => function($model) {//使用匿名函数格式化（参数为当前模型对象），也可以在模型类中定义该方法
                    $vrPics = $model['vr_pic']?explode(',',$model['vr_pic']):array();
                    $output = '';
                    foreach ($vrPics as $vrPic){
                        $pic = \backend\models\Picture::findOne($vrPic);
                        $path = \yii\helpers\Url::to('@storageUrl/image/'.$pic['path'],true);
                        $output .= Html::img($path,['width'=>'200px','height'=>'100px']);
                    }

                    return $output;
                },
                'label'=>'效果图',
                'format'=>'raw'
            ],
            [
                'attribute' => 'around_pic',
                'value' => function($model) {//使用匿名函数格式化（参数为当前模型对象），也可以在模型类中定义该方法
                    $aroundPics = $model['around_pic']?explode(',',$model['around_pic']):array();
                    $output = '';
                    foreach ($aroundPics as $aroundPic){
                        $pic = \backend\models\Picture::findOne($aroundPic);
                        $path = \yii\helpers\Url::to('@storageUrl/image/'.$pic['path'],true);
                        $output .= Html::img($path,['width'=>'200px','height'=>'100px']);
                    }

                    return $output;
                },
                'label'=>'周边图',
                'format'=>'raw'
            ],
            'commission_ad',
            'commission_percent',
            'commission_fix',
            'commission_type',
            'adviser',
            'adviser_mobile',
            'description',
            [
                'attribute' => 'address',
                'value'=>function($model){
                   $province =  \common\modelsgii\Region::findOne($model['province']);
                    $city =  \common\modelsgii\Region::findOne($model['city']);
                    return $province['fullname'].$city['fullname'].$model['address'];
                }
             ],

            'tel',
            'create_time',
            'update_time',
            'refer_start_time',
            'refer_end_time',
            [
                'attribute' => 'status',
                'value' => function($model) {//使用匿名函数格式化（参数为当前模型对象），也可以在模型类中定义该方法
                    $status = ['未审核', '已审核'];
                    return $status[$model->status];
                }
            ],
        ],
    ]) ?>

</div>

<!-- 定义数据块 -->
<?php $this->beginBlock('test'); ?>
jQuery(document).ready(function() {
highlight_subnav('jjr-project/index'); //子导航高亮
});
<?php $this->endBlock() ?>
<!-- 将数据块 注入到视图中的某个位置 -->
<?php $this->registerJs($this->blocks['test'], \yii\web\View::POS_END); ?>

